<!--
 * @Author: Aaron
 * @Date: 2022-02-18 10:02:44
 * @LastEditors: YanMeng
 * @LastEditTime: 2022-11-21 10:24:02
 * @Description: file content
 * @FilePath: \ias_ui\src\views\coi\spuChannelInventory\components\WalMartGoesHome.vue
 * @Company: 沃尔玛
-->
<template>
  <div>
    <search-head
      :search-list="searchList"
      :search-data="searchData"
      :options="options"
      @handleSearch="handleSearch"
      @handleReset="handleReset"
      @handleDownload="handleDownload('SPU沃尔玛到家商品库')"
      @addition="addition"
    />
    <ess-table
      ref="table"
      :thead-list="WalMartGoesHome"
      :other-container-box="otherContainerBox"
      :resize-observer-ele="resizeObserverEle"
      :total="total"
      :data-list="dataList"
      :page-params="pageParams"
      row-key="spuCode"
      @handlePageChange="requestData"
      @handleEdits="handleEdits"
      @operationLog="operationLog"
      @selectionChange="selectionChange"
    >
      <el-button slot="right" type="primary" size="mini" round @click="addSpuClick">新增</el-button>
      <el-button slot="right" type="primary" size="mini" :disabled="selectTable.length < 1" round @click="release">发布</el-button>

      <template v-slot:productName="{ scope }">
        <span class="el-button--text el-button--mini" @click="goSpuDetailsNew(scope)">{{ scope.row.spuName }}</span>
      </template>
    </ess-table>
    <purchaseLog v-model="logVisible" width="900px" :title="title" :thead-list="operationLogTableHeaderList" :data-list="operationLogTableList" />
    <add-spu ref="addSpuRef" />
  </div>
</template>

<script>
import searchHead from '@/components/searchHead/searchHead.vue'
import essTable from '@/components/eTable/eTable.vue'
import { WalMartGoesHome } from '../../commonJs/spuWarehouseTableHead'
import { releaseStatus as lastPushResult } from '@/views/coi/commonJs/dictionary.js'
import { tableParams, searchHeaderEvent } from '@/components/eTable/js/mixins.js'
import { checkBoxFun } from '@/views/coi/commonJs/publicMethod.js'
import { requestTableDataFun, getLogs, handleEditMinxin, spuDetail } from '../js/requestMixins'
import purchaseLog from '@/components/dialogTableInfo/dialogTableInfo.vue'
import bus from '@/utils/eventBus.js'
import addSpu from '@/views/coi/spuChannelInventory/components/addSpuTo.vue'
import { rePushSpuData } from '../js/requser.js'
export default {
  name: 'WalMartGoesHome',
  components: {
    searchHead,
    essTable,
    purchaseLog,
    addSpu
  },
  mixins: [tableParams, checkBoxFun, requestTableDataFun, searchHeaderEvent, getLogs, handleEditMinxin, spuDetail],
  props: {
    menuName: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      channelId: '12',
      searchData: {},
      otherContainerBox: ['.app-container', '.checkComponent', '.tab'],
      resizeObserverEle: ['.app-main', '.app-container'],
      searchList: [
        { label: 'UPC(不含检验码)', type: 'textarea', value: 'skuCodeList' },
        { label: 'SPU名称', type: 'input', value: 'channelSpuName' },
        { label: '部门', type: 'input', value: 'deptNbr' },
        { label: '发布状态', type: 'select', value: 'lastPushResult' },
        { label: '渠道商品编号', type: 'textarea', value: 'channelSpuIdList' }
      ],
      options: {
        lastPushResult
      },
      WalMartGoesHome,
      selectTable: []
    }
  },
  methods: {
    goDetails({ row }) {
      console.log(row)
      bus.$emit('setTagName', row.channelSpuName)
      const id = row.spuCode
      this.$router.push({
        path: `/spuSeries/${id}/details/${this.$route.name}`
      })
    },
    addSpuClick() {
      bus.$emit('setTagName', 'WMDJ系列品新增')
      const id = Math.floor(Math.random() * 100)
      this.$router.push({
        path: `/addspu/${id}/modify`
      })
    },
    goSpuDetailsNew({ row }) {
      const spuCode = row.spuCode
      console.log('row', spuCode)
      bus.$emit('setTagName', row.spuName)
      const query = {}
      query.status = 'edit'
      query.disabled = 'disabled'
      query.spuCode = spuCode
      this.$router.push({
        path: `/addspu/${row.spuCode}/${query.disabled}`,
        query
      })
      // this.gotoAddSpu(spuCode, true, row.spuName)
    },
    handleEdits({ row }) {
      // 前往编辑
      bus.$emit('setTagName', row.spuName)
      const query = {}
      query.status = 'edit'
      // query.disabled = 'disabled'
      query.spuCode = row.spuCode
      query.menuName = 'safeguard'
      this.$router.push({
        path: `/addspu/${row.spuCode}/${query.status}`,
        query
      })
    },
    // 跳转路由
    gotoAddSpu(spuCode, isDisabled, spuName = 'WMDJ系列品编辑') {
      bus.$emit('setTagName', spuName)
      const query = {}
      query.status = 'edit'
      let disabled = ''
      if (isDisabled) query.disabled = 'disabled'
      disabled = query.disabled ? query.disabled : query.status
      query.spuCode = spuCode
      this.$router.push({
        path: `/addspu/${spuName}/${disabled}`,
        query
      })
    },
    // 选中数据
    selectionChange(val) {
      const list = []
      val &&
        val.forEach((item) => {
          list.push({
            channelId: item.channelId,
            spuCode: item.spuCode,
            updateBy: item.updateBy
          })
        })
      this.selectTable = list
    },
    // 发布
    async release() {
      console.log('发布状态', this.selectTable)
      const res = await rePushSpuData(this.selectTable)
      console.log('发布状态', res)
      if (Number(res.code) === 0) {
        this.$message.success('发布成功')
        this.pageParams.pageNum = 1
        this.pageParams.pageSize = 10
        this.requestData()
        this.$refs.table.clearSelection()
      }
    }
  }
}
</script>

<style lang="scss" scoped>
/deep/ .table-header {
  padding-bottom: 10px;
}
.table-pagination .table-header[data-v-6fb0cd6f] .el-button {
  margin-right: 10px;
}
</style>
